/*
 * inet_ntoa.c
 *
 *  Created on: 2009-5-5
 *      Author: tian
 */

#include"ipaddr.h"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

char *inet_ntoa(struct in_addr inaddr){
	char *addr=malloc(16*sizeof(char));
	int i=0;
	for(;i<16;i++)
		addr[i]=0;
	i=0;
	int len=0;
	for(;i<4;i++){
		if(inaddr.part[i]<0||inaddr.part[i]>255)
			return NULL;
		sprintf(addr+len,"%d.",inaddr.part[i]);
		len=strlen(addr);
	}
	addr[len-1]='\0';
	return addr;
}
